﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using TVShow.Framework;

namespace TVShow.TestRig
{
  public class TestRig : TVShow.Framework.PluginBase
  {
    TestRigForm Form = new TestRigForm();

    public override void LoadPlugin(TVShow.Framework.DisplayManager Display) {
      base.LoadPlugin(Display);
      Form.Show();
      Form.Location = new Point(0, 0);
      if (Screen.AllScreens.Count() > 1)
        Form.Location = Screen.AllScreens[1].WorkingArea.Location;

      int left = int.Parse(INIfile.GetString("TestRig", "left", "0"));
      int top = int.Parse(INIfile.GetString("TestRig", "top", "0"));
      Form.Location.Offset(new Point(left, top));

      Form.SendClicked += new EventHandler(Form_SendClicked);
    }

    void Form_SendClicked(object sender, EventArgs e) {
      TVSMessage.Send(Form.tbSend.Text);
    }

    public override void ProcessMessage(TVSMessage Event) {
      Form.Log("Event: " + Event.Text + "\r\n");
      for (int i = 1; i < Event.Count; i++) {
        string arg = Event[i];
        Form.Log("Arg " + i.ToString() + ": " + arg + "\r\n");
      }

      if (Event.Text.ToLower() == "shutdown") {
        TVSMessage.RemovePlugin(this);
        Form.Close();
      }

    }
  }
}
